﻿using Dapper;
using Dapper.Contrib.Extensions;
using EWC.HIS.Domain;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories.Dapper;
using Volo.Abp.EntityFrameworkCore;

namespace EWC.HIS.Infrastructure
{
    public class OutptApptRegRepository : DapperRepository<HISDbContext>, IOutptApptRegRepository
    {
        public OutptApptRegRepository(IDbContextProvider<HISDbContext> dbContextProvider)
            : base(dbContextProvider)
        {
        }

        public virtual async Task<List<string>> GetPatientNames()
        {
            var dbConnection = await GetDbConnectionAsync();
            var transaction = await GetDbTransactionAsync();
            return (await dbConnection.QueryAsync<string>("SELECT TOP (1000) [PatientName] FROM [OutptApptReg].[dbo].[AppointmentRegistration]", transaction: transaction))
                .ToList();
        }

        public virtual async Task<int> InsertAsync(AppointmentRegistration appointment)
        {


            var dbConnection = await GetDbConnectionAsync();
            var transaction = await GetDbTransactionAsync();
            appointment.CreationTime= DateTime.Now;
            return await dbConnection.InsertAsync(appointment, transaction);

        }
    }

}
